function EnumWindowsProc (Wnd: HWND; lb: TListbox): BOOL; stdcall;
var
caption: array [0..128] of Char;
begin
Result := True;

SendMessage( Wnd, WM_GETTEXT, Sizeof( caption ), integer(@caption));
lb.Items.AddObject( caption, TObject( Wnd ));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 listbox1.clear;
 EnumWindows( @EnumWindowsProc, integer( listbox1 ));
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var
theClassname: Array [0..128] of Char;
Wnd: HWND;
tid, pid: DWORD;
begin
With Sender As TListbox Do Begin
  If ItemIndex >= 0 Then Begin
    Wnd:= HWND(Items.Objects[ itemindex ]);
    If Wnd <> 0 Then Begin
      Windows.GetClassname( Wnd, theClassname, Sizeof( classname ));
      tid := GetWindowThreadProcessID( Wnd, @pid );
      label2.caption :=
        Format(
          'HWND: %8.8x'#13#10+
          'Class: %s'#13#10+
          'Process ID: %8.8x'#13#10+
          'Thread ID: %8.8x',
          [Wnd, theClassname, pid, tid] );
    End;
  End;
End;
end;

function Kill(Handle : hWnd) : dword;
(*Terminate a task*)
begin
 SendMessage(Handle, WM_CLOSE, 0, 0);
end;